package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* PushLocalFileView
* */
class PushLocalFileView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mStrokeWidth0 = context.resources.getDimension(R.dimen.dp_2)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.SQUARE
            strokeJoin = Paint.Join.MITER
            style = Paint.Style.FILL_AND_STROKE
            color = context.resources.getColor(R.color.color_AACF24)
        }
    }

    private val mPath0 by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)
            mPaint0.strokeWidth = (cx / 5).coerceAtLeast(mStrokeWidth0)
            mPath0.apply {
                moveTo(cx / 2, -cy / 2)
                lineTo(0F, -cy / 2)
                lineTo(cx / 2, 0F)
                close()
                moveTo(cx / 4, -cy / 4)
                lineTo(-cx / 2, cy / 2)
            }
            drawPath(mPath0, mPaint0)
        }
    }
}